package by.andronix.logger
{
	
	import flash.utils.getQualifiedClassName;
	
	import mx.logging.ILogger;
	import mx.logging.ILoggingTarget;
	import mx.logging.Log;
	import mx.logging.targets.LineFormattedTarget;
	
	public class Logger
	{
		
		
		public static function getLogger(obj:Object):ILogger {
			return Log.getLogger( getQualifiedClassName(obj).replace('::', '.') );
		}
		
		
		private static function createLogTarget(logType: String,
												logFilters:Array,
												level:int = 0,
												includeCategory:Boolean = true,
												includeDate:Boolean = true,
												includeTime:Boolean = true): ILoggingTarget
  		{
  			
  			var target: LineFormattedTarget = LogTargetFactory.create(logType) as LineFormattedTarget;
  			
  			if(target != null)
  			{
				var filters: Array = [];
				
				target.includeCategory = includeCategory;
				target.includeDate = includeDate;
				target.includeTime = includeTime;
				target.includeLevel = true;
				target.level = level;				
				target.filters = logFilters;
  			}
  			
  			return target as ILoggingTarget;
  		}
		
		public static function addLog(  logType: String,
										logFilters:Array,
										level:int = 0,
										includeCategory:Boolean = true,
										includeDate:Boolean = true,
										includeTime:Boolean = true): void
  		{
  			var target: ILoggingTarget = createLogTarget(logType, logFilters, level, includeCategory, includeDate, includeTime);
  			
  			if(target != null)
  				Log.addTarget(target);
  				
  		}
		
		
		public static function flushAll():void {
			Log.flush();
		}
				
		
	}
}